#ifndef SIM_ENV_H
#define  SIM_ENV_H

#include <simworld.h>
#include <caction.h>
#include <cstate.h>
#include <cstateproperties.h>
#include <ctransitionfunction.h>
#include "SimAction.h"
#include <vector>
#include "creature.h"
#include "Constants.h"
#include <math.h>

class SimEnvironment: public CTransitionFunction
{



	Simworld *myworld;

	double max_force;
	double max_sim_time;

	opal::Point3r minWorld;
	opal::Point3r maxWorld;

	opal::Point3r minTerminalState;
	opal::Point3r maxTerminalState;

	int numProps;
	int exptNum;

	void defaultInit(int numContinuous);
	void defaultResetEnvironment();
	void defaultSetResetPositions();

	bool simEnvFailed;


public:

	int rewardType;

	pthread_t mainThreadId;

	pthread_barrier_t simBarrier;

	const static int BALL_GOAL = 0;
	const static int BALL_PUSH_GOAL = 1;

	const static int WorldType = BALL_GOAL;

	SimEnvironment(int numContinuous, int numDiscrete,  Simworld *pmyworld, int exptNum);
//	SimEnvironment(int x);


	void transitionFunction(CState *oldstate, CAction *action, CState *newState, CActionData *data = NULL);

	void getDerivationU(CState *oldstate, Matrix *derivation){}

	bool isResetState(CState *);
	bool isFailedState(CState *);

	bool isThreadFailedState(CState *);


	void getResetState(CState *resetState);

	void setResetType(int resetType){}

	opal::Point3r getMinTerminalState();
	opal::Point3r getMaxTerminalState();

	opal::Point3r getMinWorldState();
	opal::Point3r getMaxWorldState();

	int getNumProperties();
	void resetEnvironment();
	void SetResetPositions();

};

#endif
